Conditions | 4 |
Paths | 16 |
Total Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /** |
||
30 | Analysis.prototype.getFrequentText = function(activities){ |
||
31 | var countArr = { |
||
32 | question : {}, |
||
33 | command: {} |
||
34 | }; |
||
35 | activities.forEach(function(act){ |
||
36 | countArr.question[act.preQ] = (countArr.question[act.preQ]||0) + 1; |
||
37 | countArr.command[act.pattern] = (countArr.command[act.pattern]||0) + 1; |
||
38 | }); |
||
39 | |||
40 | var max = 0, t = "", frequentArr = []; |
||
41 | for (var key in countArr) { |
||
|
|||
42 | for (var key1 in countArr[key]) { |
||
43 | if(max <= parseInt(countArr[key][key1])){ |
||
44 | max = countArr[key][key1]; |
||
45 | t = key1; |
||
46 | } else { |
||
47 | max = max; |
||
48 | } |
||
49 | } |
||
50 | frequentArr.push({"text": t, type: key}); |
||
51 | max = 0; |
||
52 | t= ""; |
||
53 | } |
||
54 | |||
55 | return frequentArr; |
||
56 | }; |
||
57 | |||
58 | module.exports = Analysis; |
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: